<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>案例2</title>
    <style>
        .content {
            width: 800px;
            margin: 100px auto;
        }
        
        .flex {
            display: flex;
        }
        
        .theme div {
            width: 20px;
            height: 20px;
            background-color: red;
            margin: 5px;
            cursor: pointer;
        }
        
        .theme div:nth-child(2) {
            background-color: green;
        }
        
        .theme div:nth-child(3) {
            background-color: orange;
        }
        
        .tab div {
            flex: 1;
            width: 160px;
            text-align: center;
            border: 1px solid #eee;
            margin: 0 1px;
        }
        
        .red {
            color: white;
            background-color: red;
        }
        
        .green {
            color: white;
            background-color: green;
        }
        
        .orange {
            color: white;
            background-color: orange;
        }
    </style>
</head>

<body>
    <div class="content">
        <ul>
            <li class="theme flex">
                <div onclick="changeColor('red')"></div>
                <div onclick="changeColor('green')"></div>
                <div onclick="changeColor('orange')"></div>
            </li>
            <li class="tab flex">
                <div class="bt">新闻</div>
                <div class="bt">娱乐</div>
                <div class="bt">体育</div>
                <div class="bt">电影</div>
                <div class="bt">音乐</div>
                <div class="bt">旅游</div>
            </li>
        </ul>
    </div>
    <script>
        // <!-- 179001202 张皓然 -->
        function changeColor(color) {
            let divs = document.querySelectorAll('.bt')
            divs.forEach(e => {
                e.className = "bt"
                e.className += ` ${color}`
            });
            if (color == 'red') {
                document.querySelector('body').style.backgroundColor = '#ffdddd'
            }
            if (color == 'green') {
                document.querySelector('body').style.backgroundColor = '#a3c5a8'
            }
            if (color == 'orange') {
                document.querySelector('body').style.backgroundColor = '#cdd834'
            }
        }
    </script>
</body>

</html>